package com.igoal.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.context.SecurityContextHolder;

import com.igoal.web.security.LoginStatus;

public class OnlineFilter implements Filter {

	public void init(FilterConfig filterConfig) throws ServletException {
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		String username = SecurityContextHolder.getContext().getAuthentication().getName();
		if (StringUtils.isNotBlank(username)) {
			LoginStatus.refreshStatus(username);
		}
		chain.doFilter(request, response);
	}

	public void destroy() {
	}

}
